import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2023-01-11
 * Time: 下午 20:52
 */
@WebServlet("/index")
public class IndexServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        resp.setContentType("text/html;charset=utf8");
        if(username == null || username.equals("") || password == null || password.equals("")) {
            resp.getWriter().write("输入不完整请从新输入!");
            return;
        }

        if(!username.equals("zhangsan") || !password.equals("123")) {
            resp.getWriter().write("账号或者密码输入错误请从新输入!");
            return;
        }

        HttpSession session = req.getSession(true);
        session.setAttribute("username","zhangsan");
        Integer visit = (Integer) session.getAttribute("count");
        if(visit == null) {
            session.setAttribute("count",0);
        }else {
            //什么也不做
        }
        resp.sendRedirect("login");
    }
}
